import { ref } from 'vue';
import { updateSetting, resetSetting } from '@/common/api/user.js';
export default function() {
	let timer = 0;
	// 更新
	async function update(key, value) {
		timer && clearTimeout(timer);
		timer = setTimeout(async () => {
			getApp().globalData.setting[key] = value;
			await updateSetting({
				key,
				value
			})
		}, 500)
	}
	// 恢复默认
	async function reset(obj) {
		timer && clearTimeout(timer);
		timer = setTimeout(async () => {
			let keys = [];
			for (let key in obj) {
				keys.push(key);
			}
			await resetSetting({
				keys
			})
			getApp().globalData.setting_init();
		}, 500)
	}
	return {
		update,
		reset
	}
}